// packageK/hxt/dataDisplay/dataDisplay.js
var o = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabInd:0,
    time:-1,
    selecttime:false,
    team_count:"0",//团队人数
    order_count:"0",//总单量
    team_performance:"0",//总业绩
    direct_count:"0",//总粉丝人数
    direct_list:[],//总粉丝
    month:"",
    uid:"",
    minDate: new Date(2000,1,1).getTime(),
    maxDate: new Date().getTime(),
    currentDate: new Date().getTime(),
    rewardList:[],
    total:0,
    page:1,
    isLoding:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      uid:wx.getStorageSync('uid')
      // uid:115700
    })
    var t = o.getNetAddresss("Baoxian.getTeamInfo");
    let e = this
    o._postNetWork({
        url: t,
        data:{
            uid:this.data.uid
        },
        success(l){
            let i = l.data
            if(i.result == 1){
              e.setData({
                team_count : i.data.team_count,
                order_count : i.data.order_count,
                team_performance : i.data.team_performance
              })
            }
        }
    })

    this.getDirectTeam()

  },
  selectTab(e){
    let t = e.currentTarget.dataset.tab
    if (this.data.tabInd == t) return
    this.setData({
      tabInd:t
    })
    if(t == 0){
      this.getDirectTeam()
    }else{
      this.onConfirm(1)
    }

  },
  selectDay(e){
    let t = e.currentTarget.dataset.time
    this.setData({
      time:t
    })
  },
  selectdayshow(e){
    this.setData({
      selecttime:!this.data.selecttime
    })
    let t = e.currentTarget.dataset.con
    console.log(t);
  },
  // 直推用户
  getDirectTeam(){
    var t = o.getNetAddresss("Baoxian.getDirectTeam");
    let e = this
    o._postNetWork({
        url: t,
        data:{
            uid:this.data.uid
        },
        success(l){
            let i = l.data
            if(i.result == 1){
              e.setData({
                direct_count : i.data.direct_count,
                direct_list : i.data.direct_list,
              })
            }
        }
    })
  },
  // 
  onConfirm(e){
    let d = e == 1 ? new Date() : new Date(e.detail)
    let y = d.getFullYear()
    let m = d.getMonth() + 1
    this.setData({
      month : y + "-" + (m>9?m:('0'+m)),
      rewardList:[],
      isLoding:false,
      selecttime:false
    })
    this.getFuwu()
  },
  // 获取服务费
  getFuwu(){
    this.isLoding = true
    var t = o.getNetAddresss("Baoxian.rewardList");
    let e = this
    o._postNetWork({
        url: t,
        data:{
          uid:this.data.uid,
          month:this.data.month,
          page:this.data.page,
        },
        success(l){
            let i = l.data
            if(i.result == 1){
              let arr = i.data.data
              e.setData({
                rewardList:[...e.data.rewardList,...arr],
                total: i.data.total,
                isLoding:false
              })
              if(e.data.rewardList.length >= e.data.total){
                e.setData({
                  isLoding:true
                })
              }
              console.log(i);
            }
        }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if(!this.data.isLoding && this.data.rewardList.length < this.data.total){
      this.setData({
        page:this.data.page++
      })
      this.getFuwu()
    }else{
      this.setData({
        isLoding: true
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})